/*
 * 
 *  This file is part of Sourceprojects.org Thracia.
 *  Copyright 2010 noctarius
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 * 
 */
package org.sourceprojects.thracia.util;

import java.util.HashMap;
import java.util.Map;

/**
 * @author noctarius
 * 
 */
public class SequenceCounter {
	private static final SequenceCounter INSTANCE = new SequenceCounter();

	public static final SequenceCounter getInstance() {
		return INSTANCE;
	}

	private Map<String, Integer> counter = null;

	private SequenceCounter() {
		counter = new HashMap<String, Integer>();
	}

	public synchronized Integer count(String hash) {
		if (!counter.containsKey(hash)) {
			counter.put(hash, 1);
		} else {
			counter.put(hash, counter.get(hash) + 1);
		}

		return counter.get(hash);
	}

	public synchronized Integer getCount(String hash) {
		return (counter.containsKey(hash) ? counter.get(hash) : 0);
	}
	
	public synchronized void setCount(String hash, Integer count) {
		counter.put(hash, count);
	}
}
